package second.stackandqueue;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Solution05 {
    public String removeDuplicates(String s) {
        List<Character> stack = new LinkedList<>();
        for (int i = 0; i < s.length(); i++) {
            if (stack.isEmpty() || s.charAt(i) != stack.get(stack.size() - 1)) {
                stack.add(s.charAt(i));
            } else {
                stack.remove(stack.size() - 1);
            }
        }
        char[] chars = new char[stack.size()];
        for (int i = 0; i < stack.size(); i++) {
            chars[i] = stack.get(i);
        }
        return new String(chars);
    }
}
